<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Jedrzej\Pimpable\PimpableTrait;

class StoreBargainUser extends Model
{
    use HasFactory;
    use PimpableTrait;
    use SoftDeletes;

    public $searchable = [
        'id',
        'status',
        'start_at',
        'shop_at',
    ];

    public $statusEnum = [
        'participating' => '进行中',
        'endOfActivitySuccess' => ' 已成功',
        'endOfActivityFail' => '已失败',
    ];

    /**
     * 默认倒序
     */
    protected $defaultSortCriteria = ['id,desc'];

    /**
     * 关联砍价商品模型
     */

    public function storeBargain()
    {
        return $this->belongsTo(StoreBargain::class, 'bargain_id', 'id');
    }

    /**
     * 关联用户模型
     */

    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'id');
    }

    /**
     * 关联用户帮助模型
     */

    public function userHelp()
    {
        return $this->hasMany(StoreBargainUserHelp::class, 'bargain_user_id', 'id');
    }
}
